﻿using ArticleandSiteData;

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel.Core;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Core;
using Windows.UI.ViewManagement;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;

// https://go.microsoft.com/fwlink/?LinkId=234238 上介绍了“空白页”项模板

namespace Dong
{
    /// <summary>
    /// 可用于自身或导航至 Frame 内部的空白页。
    /// </summary>
    public sealed partial class Addseriesimage : Page
    {
        public Addseriesimage()
        {
            this.InitializeComponent();
        }
        protected async override void OnNavigatedTo(NavigationEventArgs e)
        {
            DataVMClass M = new DataVMClass();
            await M.Getserieslist(listimg);
            base.OnNavigatedTo(e);
        }

        private async void add_Click(object sender, RoutedEventArgs e)
        {
            if(listimg.SelectedValue==null||string.IsNullOrEmpty(listimg.SelectedValue.ToString()))
            {
                return;
            }
            string url = "https://api.bmob.cn/1/classes/seriesimagedetail";
            Dictionary<string, string> dic = new Dictionary<string, string>();
            dic.Add("imageurl", imageurl.Text);
            dic.Add("imagedes", imagedes.Text);
            dic.Add("siteurl", siteurl.Text);
           
            dic.Add("seriesname", listimg.SelectedValue.ToString());
            bool r = await RequestHelper.addsimpleobject(url, dic);
            if (!r)
            {

            }
            else
            {
                
                imageurl.Text = string.Empty;
            }
        }

        private async void home_Click(object sender, RoutedEventArgs e)
        {
            int newViewId=0;
            CoreApplicationView newView = CoreApplication.CreateNewView();
            await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var newWindow = Window.Current;
                var newAppView = ApplicationView.GetForCurrentView();
                Frame frame = new Frame();
                frame.Navigate(typeof(MainPage));
                newWindow.Content = frame;
                newWindow.Activate();
                newViewId = newAppView.Id;
            });
           bool    viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);

        }

        private async void addcategoryimage_Click(object sender, RoutedEventArgs e)
        {
            int newViewId = 0;
            CoreApplicationView newView = CoreApplication.CreateNewView();
            await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
            {
                var newWindow = Window.Current;
                var newAppView = ApplicationView.GetForCurrentView();
                Frame frame = new Frame();
                frame.Navigate(typeof(AddImagePage));
                newWindow.Content = frame;
                newWindow.Activate();
                newViewId = newAppView.Id;
            });
            bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId);
        }
    }
}
